package com.study.ju.service.impl;

import com.study.ju.dao.transactionaltest.YcyTableMapper;
import com.study.ju.entity.transactionaltest.YcyTable;
import com.study.ju.service.transactionaltest.TestBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Created by tao on 2018/8/4.
 */
@Service
public class TestBServiceImpl implements TestBService {
    @Autowired
    private YcyTableMapper ycyTableMapper;

    @Transactional
    public void testBInsert(int num, String name) {
        //try {
            YcyTable ycyTable = new YcyTable();
            ycyTable.setName(name);
            ycyTable.setNum(num);
            ycyTableMapper.insert(ycyTable);
            if (num == 3) {
                int i = 1 / 0;// 此处会产生异常
            }
     /*   } catch (Exception e) {
            System.out.println(num + "service异常日志b");
        }*/

        System.out.println(num + "service正常执行");

    }
    @Transactional
    @Override
    public void testBInsertNoExceptionAndNoTryCatch(int num, String name) {
        YcyTable ycyTable = new YcyTable();
        ycyTable.setName(name);
        ycyTable.setNum(num);
        ycyTableMapper.insert(ycyTable);
        System.out.println(num + "service正常执行");
    }
    @Transactional
    @Override
    public void testBInsertExceptionAndNoTryCatch(int num, String name) {
        YcyTable ycyTable = new YcyTable();
        ycyTable.setName(name);
        ycyTable.setNum(num);
        ycyTableMapper.insert(ycyTable);
        if (num == 3) {
            int i = 1 / 0;// 此处会产生异常
        }


        System.out.println(num + "service正常执行");
    }
    @Transactional
    @Override
    public void testBInsertExceptionAndTryCatch(int num, String name) {
        try {
            YcyTable ycyTable = new YcyTable();
            ycyTable.setName(name);
            ycyTable.setNum(num);
            ycyTableMapper.insert(ycyTable);
            if (num == 3) {
                int i = 1 / 0;// 此处会产生异常
            }
        } catch (Exception e) {
            System.out.println(num + "service异常日志b");
        }

        System.out.println(num + "service正常执行");
    }

}
